<template>
	<div>

		<el-row>
			<!-- <el-col :span="5">
				<el-input v-model="search.customerName" placeholder="请输入要查询的姓名"></el-input>
			</el-col> -->
			<el-col>
				<!-- <el-button type="primary" icon="el-icon-search" @click="searchData()">搜索</el-button> -->
				<el-button type="primary" icon="el-icon-circle-plus-outline" plain @click="add()">添加</el-button>
			</el-col>
		</el-row>
		<el-table :data="result.tableData" style="width: 100%">
			<el-table-column label="序号" prop="dataId" width="70px"></el-table-column>

			<el-table-column label="类别" prop="category" width="230px"></el-table-column>

			<el-table-column label="数据代码" prop="dataCode" width="230px"></el-table-column>

			<el-table-column label="数据名称" prop="dataTime" width="280px"></el-table-column>


			<el-table-column label="操作" width="150px">
				<template slot-scope="scope">
					<el-button size="mini" @click="handleEdit(scope.row.dataId)">编辑</el-button>
					<el-button size="mini" type="danger" @click="handleDelete(scope.row.dataId)">删除</el-button>
				</template>
			</el-table-column>
		</el-table>

		<el-pagination style="margin-top:20px;" background layout="prev, pager, next" :total="result.total"
			:current-page.sync="query.current" :page-size="query.size" @current-change="getData()">
		</el-pagination>

		<el-dialog :title="title" :visible.sync="show">

			<DataAdd :show.sync="show" @getData="getData" :editid="editid" :key="showNum"></DataAdd>

		</el-dialog>
	</div>
</template>
<script>
	import axios from '@/utils/axiosutils.js';
	import DataAdd from './add.vue';
	export default {
		data() {
			return {
				// search: {
				// 	customerName: ''
				// },
				query: {
					current: 1,
					size: 10
				},
				result: {
					tableData: [],
					pages: 0
				},
				showNum: 0,
				show: false,
				editid: null,
				title: ''
			};
		},
		components: {
			DataAdd
		},
		created() {
			this.getData();
		},
		methods: {
			getData() {
				axios.get(
					'/maintain/list',
					resp => {
						console.log(resp.obj.records);
						let page = resp.obj;
						this.result.tableData = page.records
						this.result.total = page.total;
					},
					this.query
				);
			},
			searchData() {
				// this.query.customerName = this.search.customerName
				this.query.current = 1
				this.getData()
			},
			add() {
				this.showNum++;
				this.title = '添加用户'
				this.editid = null
				this.show = true
			},
			handleEdit(dataId) {
				this.showNum++;
				this.title = '修改用户'
				this.editid = dataId
				this.show = true
			},
			handleDelete(dataId) {
				axios.del('/maintain/del', response => {
					this.getData()
				}, {
					dataId: dataId
				})
			}
		}
	};
</script>

<style>
	.el-row {
		height: 50px;
	}

	.el-main {
		background-color: #e9eef3;
		color: #333;
		line-height: 20px !important;
	}
</style>
